<template>
	<view>
		<view class="sww-prod-list" :class="[layout == 2 ? 'list_row' : 'sww-prod-list-column']" :style="{ '--color': vuex_config.themeColor1, '--price': vuex_config.price }">
			<block v-for="(item, index) in dataList" :key="index">
				<view class="sww-prod-item" :class="parameter.hasShadow === false?'':'has_shadow'" @click="goProdDetail(item)">
					<view class="sww-prod-top">
						<view class="prod_img_relative"><u-lazy-load :image="item.logo || vuex_config.errImg" img-mode="aspectFill"></u-lazy-load></view>
						<no-stock v-if="item.stock <= 0"></no-stock>
						<!-- 两列倒计时：定位 -->
						<view v-if="item.type == 2 && layout == 1" class="flash_time"><time-diff :sale_time="item.sale_time" color="#fff" :start="item.start_date" :end="item.end_date"></time-diff></view>
					</view>
					<view class="sww-prod-content">
						<view class="sww_prod_name" :class="[vuex_config.subtitle == 1 && layout == 2 && item.type == 2 ? 'u-line-1' : 'u-line-2']">
							{{ item.name }}
						</view>

						<view class="subtitle" :class="[layout == 2 && item.type == 1?'u-line-2':'u-line-1']" v-if="vuex_config.subtitle == 1 && item.title">{{ item.title }}</view>
						<view class="sale_num" v-if="vuex_config.sales_volume == 1 && item.order_count > 0">
							{{ item.order_count || 0 }}人付款
						</view>
						<view :class="['bot_box',vuex_config.sales_volume == 1 && item.order_count > 0?'':'no_sale']">
							<view class="row_time" v-if="item.type == 2 && layout == 2">
								<!-- 倒计时 行样式 -->
								<time-diff :sale_time="item.sale_time" :start="item.start_date" :end="item.end_date"></time-diff>
							</view>
							<view class="sww-prod-bottom">
								<view class="sww-prod-price">
									<text class="u-font-26">￥</text>
									<text class="u-font-34">{{ $price(item.r_price || item.r_price === 0? item.r_price : item.price) | priceFmt(false) }}</text>
									<text class="u-font-26">{{ $price(item.r_price || item.r_price === 0? item.r_price : item.price) | priceFmt(true) }}</text>
									<text class="sww-prod-market-price" v-if="item.market_price && item.market_price > 0">￥{{ $price(item.market_price) }}</text>
									<text class="sww-prod-sale" v-if="vuex_config.sales_volume == 1 && item.order_count > 0">{{ item.order_count || 0 }}人付款</text>
								</view>
								<template v-if="item.type == 1">
									<!--  @click.stop="$showSpec(item, index)" -->
									<view class="sww-prod-cart">
										<u-icon v-if="!parameter.icon" name="e73d" custom-prefix="iconfont" color="#ffffff" size="26" top="1"></u-icon>
										<image v-else class="cart_icon" :src="parameter.icon" />
									</view>
									
								</template>
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		<sww-goods-spec v-model="specVisible" type="2" :params="specParams"></sww-goods-spec>
	</view>
</template>

<script>
import timeDiff from '@/pagecomponents/FlashSale/timeDiffNew.vue';
import noStock from '@/components/noStock.vue';
export default {
	components: {
		timeDiff,
		'no-stock': noStock
	},
	props: {
		layout: {
			type: Number,
			default: 1
		}, // 1:两列 2：行
		parameter:{
			type:Object,
			default:()=>{
				return {}
			}
		},
		dataList: {
			type: Array,
			default: []
		}
	},
	data() {
		return {
			specParams: {
				buyType: 'cart',
				prodId: ''
			},
			// proType: '', //商品下标
			flashInterval: '',
			intervalTimes: 0,
			specVisible: false
		};
	},
	filters: {
		priceFmt(price, isPoint = false) {
			let [priceInt, pricePoint] = price.split('.');
			return isPoint ? (pricePoint ? '.' + pricePoint : '') : priceInt;
		}
	},
	methods: {
		// 打开规格弹框
		$showSpec(item, index) {
			this.$login().then(() => {
				this.specParams.prodId = item.pk_id;
				this.specVisible = true;
				// this.proType = this.dataList[index].type;
			});
		},
		goProdDetail(item) {
			if (item.type == 2) {
				let currentTime = new Date().getTime();
				if (currentTime > item.end_date) {
					this.$toast({
						title: '活动已结束'
					});
					return;
				}
			}
			this.$toProd({
				...item,
				prodType: 1
			});
		}
	}
};
</script>

<style scoped lang="scss">
.sww-prod-list {
	padding: 10rpx 24rpx 0;
	width: 100%;

	.sww-prod-item {
		width: 100%;
		background-color: #ffffff;
		display: flex;

		.sww-prod-top {
			width: 230rpx;
			position: relative;
			border-radius: 12rpx 12rpx 0 0;
			overflow: hidden;
			position: relative;
			.flash_time {
				width: 100%;
				height: 50rpx;
				background-color: rgba(0, 0, 0, 0.5);
				font-size: 26rpx;
				color: #ffffff;
				padding-left: 20rpx;
				display: flex;
				align-items: center;
				position: absolute;
				left: 0;
				bottom: 0;
			}
		}

		.sww-prod-content {
			flex: 1;
			overflow: hidden;
			display: flex;
			flex-direction: column;

			.sww_prod_name {
				font-size: 30rpx;
				font-weight: 500;
			}
			.subtitle {
				color: #999;
				font-size: 24rpx;
				margin-top: 6rpx;
				line-height: 32rpx;
			}

			.sww-prod-flash {
				font-size: 24rpx;
				color: var(--color);
				font-weight: 500;
				line-height: 60rpx;
			}

			.sww-prod-bottom {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				overflow: hidden;

				.sww-prod-price {
					color: var(--price);
					font-weight: 500;
					flex: 1;
					overflow: hidden;
					font-size: 0;
					.sww-prod-market-price,
					.sww-prod-sale{
						font-size: 24rpx;
						margin-left: 12rpx;
						color: #999999;
					}

					.sww-prod-market-price {
						text-decoration: line-through;
					}
				}

				.sww-prod-cart {
					width: 40rpx;
					height: 40rpx;
					background-color: var(--color);
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
					.cart_icon {
					  width: 100%;
					  height: 100%;
					}
				}
			}
		}
	}
}
.sww-prod-list.list_row {
	background-color: #fff;
	.sww-prod-item {
		border-bottom: 1rpx solid #f5f5f5;
		padding: 20rpx 0;
		  &:first-of-type {
			padding-top: 0;
		  }
		  &:last-of-type {
			border-bottom: none;
		  }
	}
	.sww-prod-top {
		margin-right: 20rpx;
		height: 220rpx;
		.prod_img_relative {
			height: 100%;
		}
	}
	.sww_prod_name {
		padding-top: 6rpx;
	}
	.sale_num{
		display: none;
	}
	.bot_box {
		margin: auto 0;
		.row_time {
			margin-bottom: 6rpx;
		}
	}
}
.sww-prod-list.sww-prod-list-column {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	.sww-prod-item {
		width: calc(50% - 12rpx);
		flex-direction: column;
		padding: 0 0 20rpx 0;
		margin-bottom: 24rpx;
		border-radius: 12rpx;
		&.has_shadow{
			box-shadow: 0 0 10rpx #cccccc;
		}
		.sww-prod-top {
			width: 100%;
			height: 0;
			padding-bottom: 100%;
			.prod_img_relative {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				// .img_url{
				// 	width: 100%;
				// 	height: 100%;
				// }
			}
		}

		.sww-prod-content {
			padding: 0 10rpx;

			.sww_prod_name {
				padding-top: 12rpx;
				font-size: 28rpx;
			}
			.sale_num{
				font-size: 24rpx;
				color: #999999;
				margin-top: auto;
				padding-top: 4rpx;
			}
			.bot_box {
				margin: 0;
				&.no_sale{
					margin-top: auto;
				}
				.sww-prod-bottom {
					margin-top: 4rpx;
				}
				.sww-prod-sale {
					display: none;
				}
			}
		}
	}
}
</style>
